<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Destroys all data registered to a session</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.session-decode.html">session_decode</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.session-encode.html">session_encode</a></div>
 <div class="up"><a href="ref.session.html">Session 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.session-destroy" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">session_destroy</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">session_destroy</span> &mdash; <span class="dc-title">Destroys all data registered to a session</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.session-destroy-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>session_destroy</strong></span>
    ( <span class="methodparam">void</span>
   )</div>

  <p class="simpara">
   <span class="function"><strong>session_destroy()</strong></span> destroys all of the data associated
   with the current session. It does not unset any of the global variables
   associated with the session, or unset the session cookie.
   To use the session variables again, <span class="function"><a href="function.session-start.html" class="function">session_start()</a></span> has
   to be called.
  </p>
  <p class="para">
   In order to kill the session altogether, like to log the user out, the
   session id must also be unset. If a cookie is used to propagate the
   session id (default behavior), then the session cookie must be deleted.
   <span class="function"><a href="function.setcookie.html" class="function">setcookie()</a></span> may be used for that.
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.session-destroy-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.session-destroy-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4669">
    <p><strong>Example #1 Destroying a session with <var class="varname"><var class="varname"><a href="reserved.variables.session.html" class="classname">$_SESSION</a></var></var></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Initialize&nbsp;the&nbsp;session.<br />//&nbsp;If&nbsp;you&nbsp;are&nbsp;using&nbsp;session_name("something"),&nbsp;don't&nbsp;forget&nbsp;it&nbsp;now!<br /></span><span style="color: #0000BB">session_start</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">//&nbsp;Unset&nbsp;all&nbsp;of&nbsp;the&nbsp;session&nbsp;variables.<br /></span><span style="color: #0000BB">$_SESSION&nbsp;</span><span style="color: #007700">=&nbsp;array();<br /><br /></span><span style="color: #FF8000">//&nbsp;If&nbsp;it's&nbsp;desired&nbsp;to&nbsp;kill&nbsp;the&nbsp;session,&nbsp;also&nbsp;delete&nbsp;the&nbsp;session&nbsp;cookie.<br />//&nbsp;Note:&nbsp;This&nbsp;will&nbsp;destroy&nbsp;the&nbsp;session,&nbsp;and&nbsp;not&nbsp;just&nbsp;the&nbsp;session&nbsp;data!<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">"session.use_cookies"</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$params&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">session_get_cookie_params</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">setcookie</span><span style="color: #007700">(</span><span style="color: #0000BB">session_name</span><span style="color: #007700">(),&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">time</span><span style="color: #007700">()&nbsp;-&nbsp;</span><span style="color: #0000BB">42000</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$params</span><span style="color: #007700">[</span><span style="color: #DD0000">"path"</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$params</span><span style="color: #007700">[</span><span style="color: #DD0000">"domain"</span><span style="color: #007700">],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$params</span><span style="color: #007700">[</span><span style="color: #DD0000">"secure"</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$params</span><span style="color: #007700">[</span><span style="color: #DD0000">"httponly"</span><span style="color: #007700">]<br />&nbsp;&nbsp;&nbsp;&nbsp;);<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Finally,&nbsp;destroy&nbsp;the&nbsp;session.<br /></span><span style="color: #0000BB">session_destroy</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.session-destroy-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Only use <span class="function"><a href="function.session-unset.html" class="function">session_unset()</a></span> for older deprecated code
    that does not use <var class="varname"><var class="varname"><a href="reserved.variables.session.html" class="classname">$_SESSION</a></var></var>.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.session-destroy-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.unset.html" class="function" rel="rdfs-seeAlso">unset()</a> - 释放给定的变量</span></li>
    <li class="member"><span class="function"><a href="function.setcookie.html" class="function" rel="rdfs-seeAlso">setcookie()</a> - Send a cookie</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.session-decode.html">session_decode</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.session-encode.html">session_encode</a></div>
 <div class="up"><a href="ref.session.html">Session 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
